/* eslint-disable */
function checkToken(option){
    return async function(ctx,next){
        try{
            let token = ctx.request.header.token
            //校验token
            let decode = ctx.app.jwt.verify(token,ctx.app.config.jwt.secret)
            if(decode.username){
                ctx.state = {
                    username:decode.username,
                    id:decode.id
                }
                await next()
            }else{
                ctx.body={
                    code:1,
                    message:'token校验失败1'
                }
            }
        }catch(error){ 
            console.log('error',error); 
            ctx.body = {
                code:1,
                message:'token校验失败2'
            }
        }
    }
}

module.exports = checkToken